import 'package:flutter/material.dart';

class QrAnmi extends StatefulWidget {
  final double height;
  final double width;
  QrAnmi({Key key, @required this.height, @required this.width});
  @override
  _QrAnmiState createState() => _QrAnmiState();
}

class _QrAnmiState extends State<QrAnmi> with SingleTickerProviderStateMixin {
  Animation<double> animation;
  AnimationController controller;
  @override
  void initState() {
    super.initState();
    controller = new AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    animation =
        new Tween(begin: 0.0, end: widget.height - 4).animate(controller)
          ..addListener(() {
            setState(() {
              // the state that has changed here is the animation object’s value
            });
          })
          ..addStatusListener((status) {
            if (status == AnimationStatus.completed) {
              controller.reverse();
            } else if (status == AnimationStatus.dismissed) {
              controller.forward();
            }
          });
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Container(
          width: widget.width,
          height: widget.height,
          decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage("assets/richscan_border.png"),
                fit: BoxFit.fill),
            // color: Colors.blue,
          ),
        ),
        Container(
          // color: Colors.red,
          margin: EdgeInsets.only(top: animation.value),
          width: widget.width,
          height: 4.0,
          child: Image.asset("assets/richscan_wire.png"),
        ),
      ],
    );
  }

  dispose() {
    controller.dispose();
    super.dispose();
  }
}
